﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Web;
using System.Xml;
using WsdlConverter;

namespace svcutil2
{
    class Program
    {
        private const string prefix = "http://localhost:8765/wsdl2wsdl/";

        public static void Main(string[] args)
        {

            Console.WriteLine("");
            Console.WriteLine("Generated by wsdl2wsdl");
            Console.WriteLine("Yaron Naveh http://webservices20.blogspot.com/");
            Console.WriteLine("=============================================");
            Console.WriteLine("");

            var listener = new Wsdl2Listener(prefix);
            listener.Start();

            try
            {
                RunSvcUtil(args);
            }
            finally
            {
                listener.Stop();
            }


            Console.WriteLine("");
            Console.WriteLine("=============================================");
            Console.WriteLine("Generated by wsdl2wsdl");
            Console.WriteLine("Yaron Naveh http://webservices20.blogspot.com/");
            Console.WriteLine("");
        }

        private static void RunSvcUtil(string[] args)
        {
            var newArgs = new string[args.Length];
            Array.Copy(args, newArgs, args.Length);
            newArgs[newArgs.Length-1] = String.Format(
                "{0}?{1}", 
                prefix, 
                newArgs[newArgs.Length-1]);
            Utils.RunExe(@"svcutil.exe", newArgs);
        }


        
    }
}
